package com.example.lib.muchthread;

public class m_deadlock_141 {
    public static void main(String[] args) {
        Thread t1=new Thread(new Test141(true));
        Thread t2=new Thread(new Test141(false));
        t1.start();
        t2.start();
    }
}

class Test141 implements Runnable {

    private boolean flag;

    public Test141(boolean flag) {
        this.flag = flag;
    }

    @Override
    public void run() {
        if (flag) {
            synchronized (MyLock141.locka) {
                System.out.println("if  locka");
                synchronized (MyLock141.lockb) {
                    System.out.println("if  lockb");
                }
            }
        } else {
            synchronized (MyLock141.lockb) {
                System.out.println("else  lockb");
                synchronized (MyLock141.locka) {
                    System.out.println("else  locka");
                }
            }
        }
    }
}

class MyLock141 {
    static Object locka = new Object();
    static Object lockb = new Object();
}